<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./vue.js"></script>
</head>

<body>
    <div id="d1">
        <input type="text" v-model="n1">
        {{n1|myf}}
        <p v-color="color">我是好人</p>
    </div>
    <div id="d2">
        <input type="text" v-model="n2">
        {{n2|myf}}
    </div>

</body>

</html>
<script>
    // 自定义指令
    Vue.directive('color',{
        inserted(el,val){
            el.style.color=val.value;
            // console.log(el);
            
        }
    })

    Vue.filter('myf', function (val) {
        var reg = /\d/g;
        return val.replace(reg, '*');
    })
    var app = new Vue({
        el: '#d1',
        data: {
            n1: '',
            color: 'yellow'
        },

        // 属性侦听
        watch: {
            n1: function (n, o) {
                console.log(n, o);
            },
        },
    })
    new Vue({
        el: '#d2',
        data: {
            n2: '',
        }
    })
</script>